{% extends "base.html" %}
{% load static %}

{% block extra_css %}
  <link rel="stylesheet" href="{% static 'css/post_list.css' %}">
{% endblock %}

{% block content %}
<div class="forum-container">
    <h1 align="center">论坛首页</h1>
    <a href="{% url 'forum:post_create' %}" class="btn-new-post">发新帖</a>

    <!-- 列举数据库内所有帖子 -->
    {% for post in posts %}
    <div class="post-card">
        <!-- 帖子详情 -->
        <div class="details">
            <h3 class="post-title"><a href="{% url 'forum:post_detail' post.pk %}">{{ post.title }}</a></h3>
            <p class="post-content-preview">{{ post.content|truncatechars:100 }}</p>
        </div>

        <!-- 帖子发布信息： -->
         <div class="post_information">
             <div class="userInfo">
                 <img src="{{ post.author.get_avatar_url }}" alt="头像" class="post-avatar">
                <span class="post-author">{{ post.author.nickname|default:post.author.username }}</span>
             </div>

            <div class="post-meta">
                <span>发布于：</span>
                <span class="post-date">{{ post.created_at|date:"Y-m-d H:i" }}</span>
            </div>

        </div>


    </div>

    <!-- 否则输出结果 -->
    {% empty %}
    <p>暂无帖子</p>

    {% endfor %}
</div>
{% endblock %}
